package com.example.ojcodesandbox.impl;

import com.example.ojcodesandbox.codesandbox.AbstractCompileTemplate;
import com.example.ojcodesandbox.utils.CodeUtils;
import com.example.ojcommon.common.ExecuteCodeRequest;
import com.example.ojcommon.common.ExecuteCodeResponse;

import java.io.File;

public class CPPDockerCodeSandbox extends AbstractCompileTemplate {
    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        return super.executeCode(executeCodeRequest,"gcc:latest",new String[]{"./app/Main"},"g++ %s -o %s/Main");
    }

    @Override
    public void compileFile(String command, File file) throws Exception {
        String userCodePath = file.getAbsolutePath();
        String parentPath = file.getParentFile().getAbsolutePath();
        String compileCmd = String.format(command, userCodePath, parentPath);
        CodeUtils.compileProcess(compileCmd);
    }
}
